using System;
using System.Linq;
using System.Numerics;

namespace ProjectEuler.Core
{
    public class Problem56 : IProjectEulerProblem
    {
        protected BigInteger MaximumDigitalSum()
        {
            var maxSum = new BigInteger(0);
            for(int i =0;i<100;i++)
            {
                for(int j=0;j<100;j++)
                {
                    var num = DigitalSum( BigInteger.Pow(i, j));
                    if(num > maxSum)
                    {
                        maxSum = num;
                    }
                }
            }
            return maxSum;
        }

        private static BigInteger DigitalSum(BigInteger num)
        {
            var sum = new BigInteger(0);
            var digits = num.ToString();
            return digits.Aggregate(sum, (current, digit) => current + (int) char.GetNumericValue(digit));
        }

        public int Number
        {
            get { return 56; }
        }

        public string Description
        {
            get { return "What is the maximum digital sum?"; }
        }

        public string Answer
        {
            get { return MaximumDigitalSum().ToString(); }
        }
    }
}